package io.shuttle.mbe.api.impl

import io.shuttle.mbe.api.Alarms
import io.shuttle.mbe.api.Events
import io.shuttle.mbe.api.types.Value1Function
import io.shuttle.mbe.api.types.VoidFunction


class Value1Event : Events.Event<Value1Function<Alarms.Alarm>> {
    private val events = mutableListOf<Value1Function<Alarms.Alarm>>()
    override fun addListener(callback: Value1Function<Alarms.Alarm>) {
        events.add(callback)
    }

    override fun hasListener(callback: Value1Function<Alarms.Alarm>): Boolean {
        return events.contains(callback)
    }

    override fun hasListeners(): Boolean {
        return events.isEmpty()
    }

    override fun removeListener(callback: Value1Function<Alarms.Alarm>) {
        events.remove(callback)
    }

    override fun addRules(
        rules: List<Events.Rule>,
        callback: Value1Function<List<Events.Rule>>?
    ) {
    }

    override fun getRules(
        ruleIdentifiers: List<String>?,
        callback: Value1Function<List<Events.Rule>>?
    ) {
    }

    override fun removeRules(
        ruleIdentifiers: List<String>?,
        callback: VoidFunction?
    ) {
    }

    fun invoke(alarm: Alarms.Alarm) {
        events.forEach { it.invoke(alarm) }
    }
}